package org.springbus.ff.tool;

import org.springbus.ff.FFmpegCommand;
import org.springbus.ff.info.ProbeInfo;
import org.springbus.ff.util.GsonTool;

public class ProbeTools {
    public static ProbeInfo probe(String input) {
        FFmpegCommand cmd = new FFmpegCommand();
        String json = cmd.ffprobe(input);
        return GsonTool.fromJson(json, ProbeInfo.class);
    }

    /**
     * get  video/mp3  duration
     *
     * @param input
     * @return
     */
    public static String getDuration(String input) {
        ProbeInfo probeInfo = probe(input);
        if (probeInfo != null && probeInfo.getFormat() != null) {
            return probeInfo.getFormat().getDuration();
        }
        return null;
    }
}
